<template>
  <div class="box">
    <el-row type="flex">
      <el-col :span="12">
        <div class="grid-content bg-purple title" style="text-align: left">
          <el-input
            clearable
            v-model.trim="params.field"
            placeholder="请输入搜索内容"
            class="input-with-select"
            @clear="getSearchItem"
            @keydown.native.enter="getSearchItem"
            @blur="getSearchItem"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getSearchItem"
            ></el-button>
          </el-input>
        </div>
      </el-col>

      <el-col :span="12">
        <el-row type="flex">
          <el-col :span="20" :offset="12">
            <el-button type="primary" @click="Jump">+添加用户</el-button>
          </el-col>
        </el-row>
      </el-col>
    </el-row>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="industryId" label="ID" width="100">
      </el-table-column>
      <el-table-column prop="industryIcon" label="行业图标" width="300">
        <template slot-scope="{ row }">
          <el-image
            style="width: 100px; height: 100px"
            :src="row.industryIcon"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="industry" label="行业" width="300">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            style="margin-right: 10px"
            @click="roleQuery(scope.row)"
            >编辑</el-button
          >
          |
          <el-button size="mini" type="text" @click="deleteItem(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="params.currentPage"
      :page-sizes="[1, 5, 100, 200]"
      :page-size="params.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>
export default {
  data () {
    return {
      tableData: [
        {
          industryId: "1",
          industryIcon: "测试图标",
          industry: "建筑",
        },
      ],
      totalpage: 0, //总条数
      params: {
        field: '',
        currentPage: 1, //当前页
        size: 5, // 每页条数
      },
      total: 0,
    };
  },
  methods: {
    Jump () {
      this.$router.replace({ name: "add" });
    },
    handleSizeChange (val) {
      // console.log(`每页 ${val} 条`);
      this.params.size = val;
      this.getInitial();
    },
    handleCurrentChange (val) {
      this.params.currentPage = val;
      this.getInitial();
    },
    // 获取页面数据
    async getInitial () {
      let {

        data: { data },
        meta: { status },
        parameters,

      } = await this.$http.getIndustryManagement(this.params);
      if (status == 200) {
        this.tableData = data;
        this.total = parameters.totalElement
      }
    },
    // 查询
    getSearchItem () {
      this.getInitial();
    },
    roleQuery (data) {
      this.$store.commit("setIndustryId", data.industryId);
      this.$store.commit("setIndustry", data);
      this.$router.push(`/industryManagement/${data.industryId}`);
    },
    // 删除
    async deleteItem (row) {
      let res = await this.$confirm("是否删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).catch(() => { });
      if (res != "confirm") return this.$message.info("取消删除");
      let {
        meta: { status },
      } = await this.$http.getDeleteIndustry(row.industryId);
      if (status == 200) {
        this.$message.success("删除用户成功");
        // 重新刷新页面
        this.getInitial();
      }
    },
  },
  created () {
    this.getInitial();
  }
};
</script>

<style scoped lang="less">
.box {
  min-width: 1000px;
}
.el-table {
  margin-top: 20px;
}
.el-breadcrumb {
  background-color: #eaedf1;
}
.el-input {
  width: 70%;
}
</style>
